package com.erpservertwo.util;

public class Result<T> {
    private Integer code;
    private String msg;
    private T data;
    private Result() {
    }
    public final static Integer SUCCESS_CODE = 200;
    public final static Integer FAIL_CODE = 500;
    public final static String SUCCESS_MEG = "请求成功";
    public final static String FAIL_MEG = "请求失败";

    public static<T> Result<T> success(){
        Result<T> result = new Result<T>();
        result.code = SUCCESS_CODE;
        result.msg = SUCCESS_MEG;
        return result;
    }
    public static<T> Result<T> success(T data){
        Result<T> result = new Result<T>();
        result.code = SUCCESS_CODE;
        result.msg = SUCCESS_MEG;
        result.data=data;
        return result;
    }
    public static<T>  Result<T> success(Integer code, String msg){
        Result<T> result = new Result<T>();
        result.code = code;
        result.msg = msg;
        return result;
    }
    public static<T>  Result<T> success(Integer code, String msg,T data){
        Result<T> result = new Result<>();
        result.code = code;
        result.msg = msg;
        result.data=data;
        return result;
    }
    public static<T> Result<T> fail(){
        Result<T> result = new Result<>();
        result.code = FAIL_CODE;
        result.msg = FAIL_MEG;
        return result;
    }
    public static<T> Result<T> fail(T data){
        Result<T> result = new Result<>();
        result.code = FAIL_CODE;
        result.msg = FAIL_MEG;
        result.data=data;
        return result;
    }
    public static<T> Result<T> fail(Integer code, String msg){
        Result<T> result = new Result<T>();
        result.code = code;
        result.msg = msg;
        return result;
    }
    public static<T> Result<T> fail(Integer code, String msg,T data){
        Result<T> result = new Result<T>();
        result.code = code;
        result.msg = msg;
        result.data=data;
        return result;
    }
}
